package com.bstek.bdf4.mq.controller;

import com.bstek.bdf2.core.mq.publisher.BstekSendMessage;
import com.bstek.bdf2.core.mq.publisher.RabbitMQRequestEntity;
import com.bstek.bdf4.builder.Builder;
import com.bstek.bdf4.mq.core.*;
import com.bstek.bdf4.mq.pojo.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;



/**
 * @Title: BstekPubLisherController
 * @Package: com.bstek.bdf4.mq.publisher.controller
 * @Description:
 * @Author: zxq
 * @Date: 2024/2/5 - 15:11
 */

@RestController
@RequestMapping("/api/mq")
public class BstekPubLisherController {

    @Resource
    private BstekSendMessage bstekSendMessage;

    @Resource
    private RabbitMQProPerties rabbitMQProPerties;


    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/send")
    public void sendMessage(){
        RabbitMQRequestEntity info = Builder.builder(RabbitMQRequestEntity::new)
                .with(RabbitMQRequestEntity::setRoutingKey, "simple.queue")
                .with(RabbitMQRequestEntity::setData,"测试")
                .build();
        bstekSendMessage.send(info);
    }



    @GetMapping("/test")
    public void send(){
        User user = new User();
        user.setId("123");
        user.setMessage("name");
        RabbitMQRequestEntity build= RabbitMQRequestEntity.builder()
                .businessId(UUID.randomUUID().toString())
                .data(user)
                .description("测试一下配置功能")
                .sendApplicationName("rabbitmq")
                .sendTopic("rabbitmq_发送测试demo")
                .build();
        System.out.println("--------------------"+"#{rabbitMQProPerties.exchange}");
        bstekSendMessage.sendMQ(build);
//        CorrelationData correlationData = new CorrelationData();
//        correlationData.setReturnedMessage(new Message(JSONUtil.toJsonStr(build).getBytes(),  new MessageProperties()));
//        rabbitTemplate.convertAndSend(RouteDeadLetterCustomer.EXCHANGE, RouteDeadLetterCustomer.ACK, build, RabbitProducerAckConfig.messagePostProcessor, correlationData);
//        rabbitTemplate.convertAndSend(rabbitMQProPerties.getExchange(), rabbitMQProPerties.getAck(), build, RabbitProducerAckConfig.messagePostProcessor, correlationData);
    }


}
